package com.luying.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtils {

    public static String beanToJson(Object object){
        ObjectMapper mapper = new ObjectMapper();
        String mapJakcson = null;
        try {
            mapJakcson = mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return mapJakcson;
    }
    public static Object jsonToBean(String json,Class c){
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.readValue(json,c);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
